// 产品工艺路线
import request from '@/router/axios';

export const getList = (current, size, params) => {
  return request({
    url: '/api/mes-product/process/page',
    method: 'post',
    params: {
      ...params,
      current,
      size
    }
  });
};

// 产品工艺复制分页查询
export const getCopyList = (current, size, params) => {
  return request({
    url: '/api/mes-product/process/semifinished/page',
    method: 'post',
    params: {
      ...params,
      current,
      size
    }
  });
};

// 根据工艺路线ID,查询工艺路线与详情
export const getDetail = (id) => {
  return request({
    url: '/api/mes-product/process/detail',
    method: 'get',
    params: {
      id
    }
  });
};

export const remove = (row) => {
  return request({
    url: '/api/mes-product/process/remove',
    method: 'post',
    params: {
      ids: row
    }
  });
};

// 提交工艺路线
export const update = (row) => {
  return request({
    url: '/api/mes-product/process/submit',
    method: 'post',
    data: row
  });
};
// 产品工艺复制
export const copy = (id, row) => {
  return request({
    url: '/api/mes-product/process/copy?id=' + id,
    method: 'post',
    data: row
  });
};
// 查询工站列表，使用在工艺设计页面左边区域
export const getWorkstation = () => {
  return request({
    url: '/api/mes-product/apaasworkstation/workstation/list',
    method: 'get'
  });
};

// 提交产品工艺路线
export const processSubmit = (row) => {
  return request({
    url: '/api/mes-product/process/submit',
    method: 'post',
    data: row
  });
};
// 提交工单工艺路线
export const processWoSubmit = (row) => {
  return request({
    url: '/api/mes-product/processwo/submit',
    method: 'post',
    data: row
  });
};
// 根据工单号，查询工艺路线
export const processWorkRouteByWo = (workOrderNo) => {
  return request({
    url: '/api/mes-product/process/workorder-route/get-by-wo',
    method: 'get',
    params: {
      workOrderNo
    }
  });
};

// 根据产品编码，查询产品工艺
export const processProductRouteByPartno = (workOrderNo) => {
  return request({
    url: '/api/mes-product/process/product-route/get-by-part-no',
    method: 'post',
    data: {
      workOrderNo
    }
  });
};

export const processProductRouteByWorkorder = (params) => {
  return request({
    // url: '/api/mes-product/process/get-workorder-process',
    url: '/api/mes-product/processwo/detail',
    method: 'get',
    params
  });
};

export const getProductPackingDetailList = (productPackingConfigId) => {
  return request({
    url: '/api/mes-admin/productpackingconfig/detail/tree',
    method: 'get',
    params: {
      productPackingConfigId
    }
  });
};

export const processUpdate = (row) => {
  return request({
    url: '/api/mes-product/process/route/updateById',
    method: 'post',
    data: row
  });
};

export const getBomVersion = (row) => {
  return request({
    url: '/api/mes-admin/bom/info-by-masterIds',
    method: 'post',
    data: row
  });
};

export const getAllSection = () => {
  return request({
    url: '/api/mes-product/work-section/all-section',
    method: 'get'
  });
};

export const getProcessDetail = (id) => {
  return request({
    url: '/api/mes-product/process/getById',
    method: 'get',
    params: {
      id
    }
  });
};

export const getProcessAllVersion = (id) => {
  return request({
    url: '/api/mes-product/process/detail/all',
    method: 'get',
    params: {
      id
    }
  });
};

export const processAudit = (data) => {
  return request({
    url: '/api/mes-product/process/isAudit',
    method: 'post',
    data: data
  });
};

export const paramDetail = (data) => {
  return request({
    url: '/api/blade-system/param/detail?paramKey=process.isAudit',
    method: 'get'
  });
};

export const getProcessLog = (workOrderNo) => {
  return request({
    url: '/api/blade-log/operation/work/order/process',
    method: 'get',
    params: {
      workOrderNo
    }
  });
};

export const getStationList = (partMasterId) => {
  return request({
    url: '/api/mes-product/process/route/id',
    method: 'get',
    params: {
      partMasterId
    }
  });
};

export const getProcessDetailById = (id) => {
  return request({
    url: '/api/mes-product/process/detail',
    method: 'get',
    params: {
      id
    }
  });
};

export const exprot = ({ data }) => {
  return request({
    url: '/api/blade-resource/attach/export-template',
    method: 'POST',
    data: data,
    responseType: 'blob'
  });
};

export const getWorkSectionByPartId = (params) => {
  return request({
    url: '/api/mes-product/process/work-section/getByPartId',
    method: 'get',
    params: params
  });
};

export const getImportPage = (params, data) => {
  return request({
    url: `/api/mes-product/process/import/page?${params}`,
    method: 'post',
    data: data
  });
};

export const getPackingDetail = (id) => {
  return request({
    url: '/api/mes-admin/product/packing/config/detail',
    method: 'get',
    params: {
      id
    }
  });
};

// export const getSectionDetail = (sectionId) => {
//   return request({
//     url: '/api/mes-product/section/binding-detail',
//     method: 'get',
//     params: {
//       sectionId
//     }
//   })
// };

export const getSectionDetail = (id) => {
  return request({
    url: '/api/mes-product/work-section/detail',
    method: 'get',
    params: {
      id
    }
  });
};

export const getSectionByPartId = (partId) => {
  return request({
    url: '/api/mes-product/part-master-section/get-by-part',
    method: 'get',
    params: {
      partId
    }
  });
};

// 工单号 查询对应的用料清单
export const getImoBySourceNo = (sourceNo) => {
  return request({
    url: '/api/mes-warehouse/sheetheader/detail',
    method: 'get',
    params: {
      sheetType: 'IMO',
      sourceType: 'WORKORDER',
      sourceNo
    }
  });
};

// 用料清单id 请求 用料清单上的半成品数据
export const getImoPageBySheetHeaderId = (sheetHeaderId) => {
  return request({
    url: '/api/mes-warehouse/sheet-detail/list',
    method: 'get',
    params: {
      partType: 'SEMIFINISHED',
      sheetHeaderId: sheetHeaderId
    }
  });
};

export const getKeyMaterialConfigByRouteId = (routeId) => {
  return request({
    url: '/api/mes-product/assemble-key-material-config/list-by-routeId',
    method: 'get',
    params: {
      routeId
    }
  });
};

export const getKeyMaterialConfigByProcessId = (processId, routeCode) => {
  return request({
    url: '/api/mes-product/assemble-key-material-config/list-by-processId-routeCode',
    method: 'get',
    params: {
      processId,
      routeCode
    }
  });
};

export const checkKeyMaterialConfig = (data) => {
  return request({
    url: `/api/mes-product/processroute/check/assemble-key-material/edit?workOrderId=${data.workOrderId}&routeCode=${data.routeCode}&processType=${data.processType}`,
    method: 'post',
    data: data.newKeyMaterialList
  });
};
